Example Program
Heaviest Increasing Subsequence
Heaviest increasing subsequence code example
This code example illustrates the heaviest increasing subsequence algorithm
1#include <seqan/graph_algorithms.h>
2#include <iostream>
3
4using namespace seqan;
5
6
7int main() {
Creation of a simple sequence and corresponding weights
8    String<char> seq("zeitgeist");
9    String<unsigned int> weights;
10    fill(weights, length(seq), 1);
11    assignProperty(weights, 2, 10);
Out-parameter: A string of positions belonging to the heaviest increasing subsequence
12    String<unsigned int> pos;
Heaviest increasing subsequence and the corresponding weight
13    unsigned int w = heaviestIncreasingSubsequence(seq, weights, pos);
Console Output
14    for(int i = 0; i< (int) length(seq); ++i) {
15        std::cout << seq[i] << "(Weight=" << getProperty(weights, i) << "),";
16    }
17    std::cout << std::endl;
18    std::cout << "His: " << std::endl;
19    for(int i = length(pos)-1; i>=0; --i) {
20        std::cout << seq[pos[i]] <<  ',';
21    }
22    std::cout << "(Weight=" << w << ')' << std::endl;
23    return 0;
24}
SeqAn - Sequence Analysis Library - www.seqan.de